	var form = layui.form;
	var arr = [];
	form.render();
    form.on('checkbox()',function(data){
	    $('input[type=checkbox]:checked').each(function() {
	      arr_box = {}
	      //属性的标题
	      title = $(this).attr('title');
	      //属性id
	      attr_id = $(this).val();
	      //name_id
	      name = $(this).attr('name');
	      tmp = {};
	      tmp['title'] = title;
	      tmp['attr_id'] = attr_id;
	      if($.isArray(arr[name])){
	      	arr[name].push(tmp);
	      }else{
	      	arr[name] = [];
	      	arr[name].push(tmp);
	      }
	    });
	    data = {};
	    data['data'] = arr;
	    data['name'] = $('input[name=name]').val();
		//提交
		$.ajax({
			url:url_set+'/plugin/goods/goods_spec/spectable.html',
			data: data,
			type:'post',
			success:function(data){
				$('#spec_table').html(data);
				// form.render();
				render();
			},
			error:function()
			{
				layer.msg('系统错误',{icon:2,time:1500});
			}
		});
	    arr = [];
    });
    //选择触发
	form.on('select(cat)', function(data){
		let selectText=data.elem[data.elem.selectedIndex].value;//得到被选中的文本值
	    data = {};
	    data['name'] = $('input[name=name]').val();
	    data['cid'] = selectText;		
		//提交
		$.ajax({
			url:url_set+'/plugin/goods/goods_spec/specchoose.html',
			data: data,
			type:'post',
			success:function(data){
				$('#spec').html(data);
				render();
			},
			error:function()
			{
				layer.msg('系统错误',{icon:2,time:1500});
			}
		});        
    });

	var upload = layui.upload; //得到 upload 对象
	// form.render();
	render();
	function render(){
		upload.render({
		  elem: '.upimg'
		  ,url:url_set+'/plugin/goods/goods_spec/pzUpload.html'
		  ,accept:'image'
		  ,auto:true
		  ,before:function(obj){
		  	//选择后到上传前的事件
		    var item = this.item;
		    // 预览
		    obj.preview(function(index,file,result) {
		        // $(item).attr('src',result);
		        $(item).parent().find('img').attr('src',result);
		    }); 	
		  }
		  ,done: function(res, index, upload){
		    //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
		    var item = this.item;
		    // console.log(item);
			if(res != null){
		        //将控制器返回的路径放入隐藏的input中
		        // $(item).parent().find("input[name=image]").val(res.save);
		        $(item).parent().find('input').val(res.save);
		        // $('#pic_save').val(res.save);        		
		        layer.msg('上传成功');
			}else{
				layer.msg('上传失败');
			}    
		  }
			,error:function(index,upload) {
			    layer.msg('上传失败');
			}
		}) 
	}    